<template>
    <h2>添加</h2>
    <table>
        <tr>
            <td>
                理财名称:
            </td>
            <td>
                <input type="text" v-model="F_Name" id="F_Name" />
            </td>
        </tr>
        <tr>
            <td>
                年收益:
            </td>
            <td>
                <input type="text" v-model="F_APY" id="F_APY" />
            </td>
        </tr>
        <tr>
            <td>
                理财最低金额:
            </td>
            <td>
                <input type="text" v-model="F_MinMoney" id="F_MinMoney" />
            </td>
        </tr>
        <tr>
            <td>
                理财人数:
            </td>
            <td>
                <input type="text" v-model="F_Num" id="F_Num" />
            </td>
        </tr>
        <tr>
            <td>
                风险等级:
            </td>
            <td>
                <select v-model="F_Level">
                    <option value="-1">--请选择--</option>
                    <option value="0">低风险</option>
                    <option value="1">中风险</option>
                    <option value="2">高风险</option>

                </select>
            </td>
        </tr>
        <tr>
            <td>
                利息编号:
            </td>
            <td>
                <select v-model="I_Id">
                    <option value="0">--请选择--</option>
                    <option v-for="item in opt" :key="I_Id" :value="item.I_Id">{{ item.I_Interest }}</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>

            </td>
            <td>
                <input type="button" value="添加理财" @click="Add" />
            </td>
        </tr>
    </table>
</template>
<script lang="ts" setup>
import { ref } from "vue";
import axios from "axios";
import { onMounted } from "vue";
const opt = ref([]);

onMounted(() => {
    Get();

})
const Get = () => {
    axios.get('http://localhost:15120/api/Demo/Bind')
        .then(res => {
            opt.value = res.data;
        })
        .catch(error => {
            console.log(error);
        })
}

const F_Name = ref("");
const F_APY = ref("");
const F_MinMoney = ref("");
const F_Num = ref("");
const F_Level = ref(-1);
const I_Id = ref(0);


const Add = () => {
    axios.post('http://localhost:15120/api/Demo/AddFinancingInfo', {
        F_Name: F_Name.value,
        F_APY: F_APY.value,
        F_MinMoney: F_MinMoney.value,
        F_Num: F_Num.value,
        F_Level: F_Level.value,
        I_Id: I_Id.value

    })
        .then(res => {
            if (res.data > 0) {
                alert("注册成功");
                return;
            }
            else {
                alert("注册失败");
                return;
            }

        })
        .catch(error => {
            console.log(error);
        });

}


</script>